<?php
if(!defined('IN_BSTO')){ die('[ERROR] You cannot load this page directly !!!'); }

class Category extends BaseElement
{
	private $cid = '';
	private $name = '';
	private $weight = '';
	private $status = '';
    
	function __construct() {
		$argv = func_get_args();
		switch( func_num_args() )
		{
			default:
				break;
			case 1:
				self::__construct1($argv[0]);
				break;			
		}
	}
	
	function __construct1($db) {
		$this->db = $db;
		
	}    
	
    public function set($name, $value)
    {
        $this->$name = $value;
    }
    
    public function get($name)
    {
        return $this->$name;
    }
    
	function init($name, $weight, $status) {		
		$this->name = $name;
		$this->weight = $weight;
		$this->status = $status;
	}
	
    public function save()
    {
    	if ($this->db != null) {
					$this->db->startConnection();
	        if ($this->cid != '') {
	        	$this->db->dbQuery("UPDATE category SET 	cid = ".var_export($this->cid, true).",
	        										name = ".var_export($this->name, true).",
	        										weight = ".var_export($this->weight, true).",
	        										status = ".var_export($this->status, true)."
	        				WHERE cid = ".var_export($this->cid, true).";");
	        }
	        else {
	        	$this->db->dbQuery("INSERT INTO category (name, weight, status)
	        						VALUES(".var_export($this->name, true).","
	        								.var_export($this->weight, true).", "
	        								.var_export($this->status, true).");");
	        }
	        $this->db->closeConnection();
    	}
    	else {
    		echo "Error: Connect to DataBase";
    	}
    }

    public function delete()
    {
    	if ($this->db != null && $this->db->connection) {
        	$db->dbQuery("DELETE FROM category WHERE cid = ".$this->cid.";");
    	}
    }
}

?>